//
//  MineViewController.m
//  ZCooking
//
//  Created by 韩旭 on 16/8/26.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "MineViewController.h"
#import "HX_Macro.h"
#import "UIView+Frame.h"
#import "SelfSizeTools.h"
#import "MineTableViewCell.h"
#import "SetUpViewController.h"
#import "HXFunctionCell.h"
#import "HXLoginViewController.h"

#define kTableView @"tableView"
@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *tableHeadView;
@property (nonatomic, strong) UIImageView *barImageView;
@property (nonatomic, strong) UILabel *lableTitle;
@property (nonatomic, strong) UIView *viewTabar;
@property (nonatomic, strong) UIImageView *headImg;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *name;
@property (nonatomic, strong) UILabel *detail;
@end

@implementation MineViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:0];
    self.viewTabar = [[UIView alloc] init];
    _viewTabar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
    [self creatTableView];
    [self.view addSubview:_viewTabar];
    self.lableTitle = [[UILabel alloc] init];
    self.lableTitle.text = @"我的";
    _lableTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.f];
    _lableTitle.HX_height = 64;
    _lableTitle.HX_width = [SelfSizeTools selfSizeHeightWithString:@"我的" height:44 Font:[UIFont systemFontOfSize:17]];
    _lableTitle.textAlignment = 1;
    _lableTitle.centerX = _viewTabar.centerX;
    [self.viewTabar addSubview:_lableTitle];
    UIButton *setUp = [UIButton buttonWithType:UIButtonTypeCustom];
    setUp.frame = CGRectMake(SCREEN_WIDTH * 0.9, 0, 20, 20);
    setUp.centerY = _lableTitle.centerY;
    [setUp setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateNormal];
    [self.viewTabar addSubview:setUp];
}
- (void)creatLoginMainView {

}
- (void)creatTableViewHeadView {
    UIImageView *imageBack = [[UIImageView alloc] init];
    self.tableHeadView = [[UIView alloc] init];
    imageBack.userInteractionEnabled = YES;
    _tableHeadView.HX_height = 250;
    _tableHeadView.HX_width = SCREEN_WIDTH;
    imageBack.frame = self.tableHeadView.bounds;
    imageBack.image = [UIImage imageNamed:@"myBackgroundImage"];
    [self.tableHeadView addSubview:imageBack];
    _tableHeadView.backgroundColor = [UIColor redColor];
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, imageBack.HX_height * 0.7,SCREEN_WIDTH,  imageBack.HX_height - imageBack.HX_height * 0.7)];
    self.backView.backgroundColor = [UIColor colorWithWhite:0.702 alpha:0.699];
    [imageBack addSubview:_backView];
    self.headImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, -25, 50, 50)];
    self.headImg.userInteractionEnabled = YES;
    self.headImg.image = [UIImage imageNamed:@"userHeadImage"];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addImageView)];
    [self.headImg addGestureRecognizer:tap];
    
    [self.backView addSubview:_headImg];
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(self.headImg.HX_x + self.headImg.HX_width + 20, 0, 100, 20)];
    _name.text = @"韩旭";
    [self.backView addSubview:_name];
    self.detail = [[UILabel alloc] initWithFrame:CGRectMake(self.headImg.HX_x, self.headImg.HX_height / 2 + 5, SCREEN_WIDTH - self.headImg.HX_x, 20)];
    self.detail.font = [UIFont systemFontOfSize:13];
    self.detail.textColor = [UIColor darkGrayColor];
    self.detail.text = @"每个吃货都是有背景的，介绍下自己吧";
    [self.backView addSubview:self.detail];
}
- (void)addImageView {
    HXLoginViewController *login = [[HXLoginViewController alloc] init];
    login.modalTransitionStyle = 2;
   [self presentViewController:login animated:YES completion:^{
   }];
}
- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT + 20) style:0];
    self.tableView.bounces = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self creatTableViewHeadView];
    self.tableView.tableHeaderView = _tableHeadView;
    [self.view addSubview: _tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"MineTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"tableReuse"];
    [_tableView registerNib:[UINib nibWithNibName:@"HXFunctionCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HXFunctionCell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
    MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableReuse"];
    return cell;
    } else {
        HXFunctionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXFunctionCell"];
        [cell.collectionBtn addTarget:self action:@selector(addBtn:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
}
- (void)addBtn:(UIButton *)btn {
    SetUpViewController *setup = [[SetUpViewController alloc] init];
    [self.navigationController pushViewController:setup animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offset_y = scrollView.contentOffset.y;
    CGFloat alpha = (offset_y + 20) / 200.0f;
    CGFloat colorF = 1 - alpha;
    self.viewTabar.backgroundColor = [UIColor colorWithWhite:0.955 alpha:alpha];
    UIButton *setUp = [UIButton buttonWithType:UIButtonTypeCustom];
    [setUp setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateNormal];
    setUp.HX_height = 20;
    setUp.HX_width = 20;
    self.lableTitle.textColor = [UIColor colorWithWhite:colorF alpha:1.000];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//